/*
    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef CONTROL_H
#define CONTROL_H

#include "gamestate.h"
#include <map>

/*
 * 棋盘控制器
 * 用以“下棋游戏”进行建模，模拟一个下棋的人工智能
 */
class Control
{
public:
    typedef std::map<unsigned long, State *> StateMap;
    enum TYPE {BEAST = 1, HUMAN = 2};

public:
    // 建立一个 width x height 的棋盘控制器
    Control(unsigned width, unsigned height);
    // 敌手下子于 (x,y) 位置
    bool beast(unsigned x, unsigned y);
    // 本方下子于 (x,y) 位置
    bool human(unsigned x, unsigned y);
    // 提示下一步下子于何处才是最好
    bool tip(unsigned& x, unsigned& y);

    int check_finish();
    bool check_success();
    bool check_fail();

private:
    // 查找指定ID号的状态，若没有则自动创建该状态
    State * find_state(unsigned long id);
    // 根据现有的_current_id，计算出下子后的新id
    unsigned long pos2id(unsigned x, unsigned y, TYPE type);

private:
    StateMap _state_pool;
    unsigned long _current_id;
};

#endif // CONTROL_H
